<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="btn">点我删除cookie</button>
    <script>
        function getDay(day){
            let date=new Date()
            let d=date.getDate()
            date.setDate(d+day)
            return date
        }
        //设置cookies
        function setCoo(name,value,{expires,path,domain}){
            console.log(name,value)
           let nameC=encodeURIComponent(name)
           let valuC=encodeURIComponent(value)
           let coo=`${nameC}=${value}`
           if(express){
               coo+=';'+'express='+getDay(expires)
           }
           if(path){
               coo+=';'+'path='+path
           }
           if(domain){
               coo+=';'+'domain='+domain
           }
           console.log(coo)
           document.cookie=coo
        }

        //获取cookies
        function getCoo(name){
            let cookie=decodeURIComponent(document.cookie)
           let start=cookie.includes(name+'=')
           if(start==-1){
               return null
           }else{
               let end=document.cookie.includes(';',start)
               if(end==-1){
                   end=cookie.length
               }else{
                   let str=cookie.substring(start,end)
                   return str
               }
           }
        }

        //删除cookie
        function removeCoo(name){
            document.cookie=encodeURIComponent(name)+'=;expires='+new Date(0)
        }
        
        setCoo('lu','lujian',7)




        let btn=document.getElementsByClassName('btn')
        // btn.onclick=()=>{
        //     removeCoo(l
        // }

    </script>
</body>
</html>